$(function(){
	$("form")[0].reset();
	$("form")[1].reset();
	$("#send_time").datepicker({
			showOn: "button",
			buttonImage: "../images/calendar.gif",
			buttonImageOnly: true
	});
	$("#from").datepicker({
			showOn: "button",
			buttonImage: "../images/calendar.gif",
			buttonImageOnly: true
	});
	$("#to").datepicker({
			showOn: "button",
			buttonImage: "../images/calendar.gif",
			buttonImageOnly: true
	});
	$("div.item input[type=checkbox]").each(function(index) {
	  if($(this).attr("checked") == "checked"){
	  	$(this).parent().addClass('item_selected');
	  }
	});
	$("div.item input[type=checkbox]").live("click",function(){
		var selected = $(this).attr("checked");
		//alert(selected);
		if( selected == "checked"){
			$(this).parent().addClass('item_selected');
		} else {
			$(this).parent().removeClass('item_selected');
		}
	});
	$(".move_btn").click(function(){
		var type = $(this).attr("name");
		//alert(type);
		if( type == "msg_to_right"){
			var items = $("#left_cellphone .item").children("input[type=checkbox]");
			var selectedItems = [];
			$.each(items, function(index, value) {
			  if($(value).attr("checked") == "checked") {
			  	var item = $(value).parent();
			  	selectedItems.push(item);
			  }
			});
			$.each(selectedItems, function(index, value) {
			  	
			    $(value).remove();
			  	$("#right_cellphone").append($(value).clone());
			});
		} else if( type == "msg_to_left") {
			var items = $("#right_cellphone .item").children("input[type=checkbox]");
			var selectedItems = [];
			$.each(items, function(index, value) {
			  if($(value).attr("checked") == "checked") {
			  	var item = $(value).parent();
			  	selectedItems.push(item);
			  }
			});
			$.each(selectedItems, function(index, value) {
			  	
			    $(value).remove();
			  	$("#left_cellphone").append($(value).clone());
			});
		} else if( type == "rotate_to_right") {
			var items = $("#rleft_cellphone .item").children("input[type=checkbox]");
			var selectedItems = [];
			$.each(items, function(index, value) {
			  if($(value).attr("checked") == "checked") {
			  	var item = $(value).parent();
			  	selectedItems.push(item);
			  }
			});
			$.each(selectedItems, function(index, value) {
			  	
			    $(value).remove();
			  	$("#rright_cellphone").append($(value).clone());
			});
		} else if( type == "rotate_to_left") {
			var items = $("#rright_cellphone .item").children("input[type=checkbox]");
			var selectedItems = [];
			$.each(items, function(index, value) {
			  if($(value).attr("checked") == "checked") {
			  	var item = $(value).parent();
			  	selectedItems.push(item);
			  }
			});
			$.each(selectedItems, function(index, value) {
			  	
			    $(value).remove();
			  	$("#rleft_cellphone").append($(value).clone());
			});
		}
	});
});
